/**
 * Copyright (c) 华南农业大学信息学院蔡超敏2015版权所有
 * 
 * 文件创建时间：2015年4月9日
 */
package org.scauinfo.fpos.action.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.scauinfo.fpos.action.BaseAction;
import org.scauinfo.fpos.service.UserpermissionService;
import org.scauinfo.fpos.util.ExceptionUtil;
import org.scauinfo.fpos.util.Json;
import org.scauinfo.fpos.vo.Userpermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;

/**
 * @author 蔡超敏
 * 
 */
@Namespace("/")
@Scope("prototype")
@Controller
@Action(value = "userpermission", results = { @Result(name = "userpermission", location = "/userpermission.jsp") })
public class UserpermissionAction extends BaseAction implements
		ModelDriven<Userpermission> {

	private static final long serialVersionUID = 3088843221530537631L;
	private static final Logger logger = Logger
			.getLogger(UserpermissionAction.class);
	@Autowired
	private UserpermissionService userpermissionService;
	public Userpermission userpermission = new Userpermission();

	/**
	 * 得到数据列表
	 */
	public void grid() {
		System.out.println("Userpermission-tags ----1");
		int total = userpermissionService.getTotal();
		System.out.println("tags ----total" + total + "page" + page + "rows"
				+ rows + ", sort" + sort + ", order" + order);
		List<Userpermission> list = userpermissionService
				.findAllUserpermission(page, rows, sort, order);
		System.out.println("Userpermissiontags ----2" + list.size());
		writeJson(total, list);
		System.out.println("tags ----3");
	}

	/**
	 * 得到数据列表
	 */
	public void combogrid() {
		System.out.println("Userpermission-tags ----1");
		List<Userpermission> list = userpermissionService
				.findAllUserpermission();
		System.out.println("tags ----2" + list.size());
		writeJson(list);
		System.out.println("tags ----3");
	}

	/**
	 * 添加操作
	 */
	public void add() {
		Json result = new Json();
		try {
			userpermissionService.saveUserpermission(userpermission);
			result.setSuccess(true);
			result.setMsg("添加用户权限成功");
		} catch (Exception e) {
			logger.debug(ExceptionUtil.getExceptionMessage(e));
			result.setMsg("添加用户权限失败");
		}
		writeJson(result);
	}

	/**
	 * 修改操作
	 */
	public void edit() {
		Json result = new Json();
		try {
			userpermissionService.updateUserpermission(userpermission);
			result.setSuccess(true);
			result.setMsg("修改用户权限成功");
			result.setSuccess(true);
		} catch (Exception e) {
			logger.debug(ExceptionUtil.getExceptionMessage(e));
			result.setMsg("添加用户权限失败");
		}
		writeJson(result);
	}

	/**
	 * 删除操作
	 */
	public void remove() {
		Json result = new Json();
		try {
			System.out.println("tags ----=" + userpermission.getId());
			userpermissionService.deleteUserpermission(userpermission.getId());
			result.setSuccess(true);
			result.setMsg("删除用户权限成功");
		} catch (Exception e) {
			logger.debug(ExceptionUtil.getExceptionMessage(e));
			result.setMsg("删除用户权限失败");
		}
		writeJson(result);
	}

	@Override
	public Userpermission getModel() {
		return userpermission;
	}
}
